package kr.co.pension.exceptions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/**
 * 로그인 에러시 또는 기타 에러시 
 * @author devhw
 *
 */
public class ExceptionHandleResolver implements HandlerExceptionResolver {
	private Logger log = LoggerFactory.getLogger(this.getClass());

//	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object obj, Exception exception) {

		ModelAndView mav = new ModelAndView();
		if (exception instanceof RequiredLoginException) {
			// 로그인 필요

			RequiredLoginException re = (RequiredLoginException) exception;

			mav.setViewName("redirect:"+re.getUrl());
		} else {
			mav.setViewName("/error/500");
		}

		return mav;
	}

}
